import { CreateProgram } from "../component/Utils";
import Frame from "../model/gameObject/Frame";
import Scene from "../model/gameObject/Scene";
import colorFrag from "../shader/Mesh/color.frag";
import colorVert from "../shader/Mesh/color.vert";
import BB2XSFrag from "../shader/frame/BB2XS.frag";
import BB2XSVert from "../shader/frame/BB2XS.vert";
import ZoomFrag from "../shader/frame/Zoom.frag";
import ZoomVert from "../shader/frame/Zoom.vert";
import depthFrag from "../shader/frame/depth.frag";
import depthVert from "../shader/frame/depth.vert";
import imageFrag from "../shader/frame/image.frag";
import imageVert from "../shader/frame/image.vert";
import viewFrag from "../shader/scene/view.frag";
import viewVert from "../shader/scene/view.vert";

export default class loadShader {
    public constructor(gl: any, frame: Frame, scene: Scene) {
        this.loadFrame(gl, frame);
        this.loadScene(gl, scene);
    }

    private loadFrame(gl: any, frame: Frame) {
        frame.regProgram('color', {
            program: CreateProgram(gl, colorVert.getShader(), colorFrag.getShader()),
            attribs: ['a_Position'],
            uniforms: ['u_PvM4', 'u_ModelM4', 'u_PointSize', 'u_Color']
        });
        frame.regProgram('depth', {
            program: CreateProgram(gl, depthVert.getShader(), depthFrag.getShader()),
            attribs: ['a_Position'],
            uniforms: ['u_PvM4', 'u_ModelM4']
        });
        frame.regProgram('image', {
            program: CreateProgram(gl, imageVert.getShader(), imageFrag.getShader()),
            attribs: ['a_Position', 'a_Pin'],
            uniforms: ['u_PvM4', 'u_ModelM4', 'u_Sampler']
        });
        frame.regProgram('BB2', {
            program: CreateProgram(gl, BB2XSVert.getShader(), BB2XSFrag.getShader()),
            attribs: ['a_Position', 'a_Pin'],
            uniforms: ['u_PvM4', 'u_ModelM4', 'u_Sampler']
        });
        frame.regProgram('zoom', {
            program: CreateProgram(gl, ZoomVert.getShader(), ZoomFrag.getShader()),
            attribs: ['a_Position', 'a_Normal'],
            uniforms: ['u_PvM4', 'u_ModelM4', 'u_Sampler', 'u_EyeDir', 'u_Center']
        });

    }

    private loadScene(gl: any, scene: Scene) {
        scene.regProgram('view', {
            program: CreateProgram(gl, viewVert.getShader(), viewFrag.getShader()),
            attribs: ['a_Position', 'a_Pin'],
            uniforms: ['u_ModelM4', 'u_Sampler']
        });

        scene.regProgram('zoom', {
            program: CreateProgram(gl, ZoomVert.getShader(), ZoomFrag.getShader()),
            attribs: ['a_Position', 'a_Normal'],
            uniforms: ['u_PvM4', 'u_ModelM4', 'u_Sampler', 'u_EyeDir', 'u_Center']
        });

        scene.regProgram('image', {
            program: CreateProgram(gl, imageVert.getShader(), imageFrag.getShader()),
            attribs: ['a_Position', 'a_Pin'],
            uniforms: ['u_PvM4', 'u_ModelM4', 'u_Sampler']
        });

        scene.regProgram('color', {
            program: CreateProgram(gl, colorVert.getShader(), colorFrag.getShader()),
            attribs: ['a_Position'],
            uniforms: ['u_PvM4', 'u_ModelM4', 'u_PointSize', 'u_Color']
        });
    }
}